package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.WyFirst;
import com.ruoyi.service.fanruan.IWyFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物业集团Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/wy")
public class WyFirstController extends BaseController
{
    private String prefix = "fanruan/wy";

    @Autowired
    private IWyFirstService wyFirstService;

    @RequiresPermissions("fanruan:wy:view")
    @GetMapping()
    public String wy()
    {
        return "fanruan/wy/wy";
    }

    /**
     * 查询物业集团列表
     */
    @RequiresPermissions("fanruan:wy:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WyFirst wyFirst)
    {
        startPage();
        List<WyFirst> list = wyFirstService.selectWyFirstList(wyFirst);
        return getDataTable(list);
    }

    /**
     * 导出物业集团列表
     */
    @RequiresPermissions("fanruan:wy:export")
    @Log(title = "物业集团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WyFirst wyFirst)
    {
        List<WyFirst> list = wyFirstService.selectWyFirstList(wyFirst);
        ExcelUtil<WyFirst> util = new ExcelUtil<WyFirst>(WyFirst.class);
        return util.exportExcel(list, "wy");
    }

    /**
     * 新增物业集团
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/wy/add";
    }

    /**
     * 新增保存物业集团
     */
    @RequiresPermissions("fanruan:wy:add")
    @Log(title = "物业集团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WyFirst wyFirst)
    {
        return toAjax(wyFirstService.insertWyFirst(wyFirst));
    }

    /**
     * 修改物业集团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WyFirst wyFirst = wyFirstService.selectWyFirstById(id);
        mmap.put("wyFirst", wyFirst);
        return "fanruan/wy/edit";
    }

    /**
     * 修改保存物业集团
     */
    @RequiresPermissions("fanruan:wy:edit")
    @Log(title = "物业集团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WyFirst wyFirst)
    {
        return toAjax(wyFirstService.updateWyFirst(wyFirst));
    }

    /**
     * 删除物业集团
     */
    @RequiresPermissions("fanruan:wy:remove")
    @Log(title = "物业集团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wyFirstService.deleteWyFirstByIds(ids));
    }
}
